package com.ruoyi.lock.service.impl;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.lock.domain.APartner;
import com.ruoyi.lock.mapper.APartnerMapper;
import com.ruoyi.lock.service.IAPartnerService;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 合伙人管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-03-10
 */
@Service
public class APartnerServiceImpl implements IAPartnerService 
{
    @Autowired
    private APartnerMapper aPartnerMapper;

    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询合伙人管理
     * 
     * @param id 合伙人管理主键
     * @return 合伙人管理
     */
    @Override
    public APartner selectAPartnerById(Long id)
    {
        return aPartnerMapper.selectAPartnerById(id);
    }

    /**
     * 查询合伙人管理列表
     * 
     * @param aPartner 合伙人管理
     * @return 合伙人管理
     */
    @Override
    @DataScope(deptAlias = "d")
    public List<APartner> selectAPartnerList(APartner aPartner)
    {
//        List<APartner> aPartners = aPartnerMapper.selectAPartnerList(aPartner);
//        if(CollectionUtils.isNotEmpty(aPartners)){
//            for (APartner partner : aPartners) {
//                SysUser sysUser = sysUserMapper.selectUserById(Long.valueOf(partner.getCreateBy()));
//                partner.setUpdateBy(sysUser.getNickName());
//
//            }
//        }
        List<APartner> aPartners = aPartnerMapper.selectAPartnerList(aPartner);
        return aPartners;
    }

    @Override
    @DataScope(deptAlias = "d")
    public List<APartner> selectAPartnerList1(APartner aPartner)
    {
        return aPartnerMapper.selectAPartnerList1(aPartner);
    }

    /**
     * 新增合伙人管理
     * 
     * @param aPartner 合伙人管理
     * @return 结果
     */
    @Override
    public int insertAPartner(APartner aPartner)
    {
        Long userId = SecurityUtils.getUserId();
        aPartner.setCreateTime(DateUtils.getNowDate());
        aPartner.setCreateBy(String.valueOf(userId));

        return aPartnerMapper.insertAPartner(aPartner);
    }

    /**
     * 修改合伙人管理
     * 
     * @param aPartner 合伙人管理
     * @return 结果
     */
    @Override
    public int updateAPartner(APartner aPartner)
    {
        Long userId = SecurityUtils.getUserId();

        aPartner.setUpdateTime(DateUtils.getNowDate());
        aPartner.setUpdateBy(String.valueOf(userId));

        return aPartnerMapper.updateAPartner(aPartner);
    }

    /**
     * 批量删除合伙人管理
     * 
     * @param ids 需要删除的合伙人管理主键
     * @return 结果
     */
    @Override
    public int deleteAPartnerByIds(Long[] ids)
    {
        return aPartnerMapper.deleteAPartnerByIds(ids);
    }

    /**
     * 删除合伙人管理信息
     * 
     * @param id 合伙人管理主键
     * @return 结果
     */
    @Override
    public int deleteAPartnerById(Long id)
    {
        return aPartnerMapper.deleteAPartnerById(id);
    }

    @Override
    public int getPartnerTotal() {
        return aPartnerMapper.getPartnerTotal();
    }

    @Override
    public JSONObject selectPartnerCount() {
        return aPartnerMapper.selectPartnerCount();
    }
}
